﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using System.Net.Sockets;
using Modbus.Device;

namespace VFTray
{
    public partial class WndDebug1 : Form
    {
        /**************通讯配置相关*****************/
        private TcpClient tcpClient = null;
        private IModbusMaster master;                            //MODBUSRTU主站字段

        bool isSendData = false;
        ushort sendCmd = 0;

        private int flat_lightA;                         //灯A状态
        private int flat_lightB;                         //灯B状态


        public WndDebug1()
        {
            InitializeComponent();

            Load += (object sender, EventArgs e) =>
             {
                 
             };
            checkBox1.CheckedChanged += (s, e) =>
            {
                foreach (var feed in GlobalParams.PC.Feeders)
                    feed.CV.SetDebug(checkBox1.Checked);
            };

            FormClosing += (s, e) =>
              {
                  if (tcpClient == null || tcpClient.Connected == false) return;
                  ushort[] SysReg = null;
                  Read0x03CmdFun(0, 3, ref SysReg);
                  int sysSt = SysReg[1] & 0X0F;
                  if (sysSt != 0)
                  {
                      isSendData = true;
                      sendCmd = 15;                                              //关闭平台
                      Send0x06CmdFun(0x05, 0x00);                     //关闭料仓
                      Send0x06CmdFun(0x06, 0X00);
                  }

                  if (tcpClient != null && tcpClient.Connected)
                  {
                      master.WriteSingleRegister(GlobalParams.zhvalue, 0x06, 0x00);                    //关闭灯光
                      master.WriteSingleRegister(GlobalParams.zhvalue, 0x05, 0x00);                              //关闭料仓
                      master.WriteSingleRegister(GlobalParams.zhvalue, 0x08, 0x00);                               //关闭平台
                  }
              };
            //ComboBox[] comboBoxes = new ComboBox[4];
            //for(int i=0;i<comboBoxes.Length;i++)
            //{
            //    comboBoxes[i] = new ComboBox();
            //    comboBoxes[i].Name = "cmbSTEP"+i+1;
            //    comboBoxes[i].FormattingEnabled = true;
            //    comboBoxes[i].Location = new System.Drawing.Point(74, 81*(i+1)*51);
            //    comboBoxes[i].Size = new System.Drawing.Size(79, 23);
            //    comboBoxes[i].TabIndex = 6+i;
            //}

            if (flat_lightA == 1)
            {
                labelLightStateA.Text = "开";
            }
            else
            {
                labelLightStateA.Text = "关";
            }
        }


        internal void OnUiTimer()
        {
        }

        #region UI_Clicked
        private void btnETHConnect_Click(object sender, EventArgs e)
        {
            GlobalParams.zhvalue = (byte)Convert.ToInt32(textBoxETHID.Text.Trim());
            if (textBoxETHID.Text == "")                                  //站号
            {
                MessageBox.Show("站号不为空");
                return;
            }

            if (Convert.ToInt32(textBoxETHID.Text.Trim()) > 255)
            {
                MessageBox.Show("站号不能大于255");
                return;
            }
            //UserData.IdNumber = Convert.ToInt32(tbETHID.Text);

            if (tcpClient != null)
                tcpClient.Close();

            tcpClient = new TcpClient();                            //网口通讯

            try
            {
                if (!tcpClient.ConnectAsync(textBoxETHIPAddress.Text.Trim(), Convert.ToInt32(textBoxETHPort.Text.Trim())).Wait(500))
                {
                    if (tcpClient != null)
                    {
                        tcpClient.Close();
                        MessageBox.Show("连接失败");

                    }
                }
                else
                {
                    master = ModbusIpMaster.CreateIp(tcpClient);
                    master.Transport.ReadTimeout = 300;
                    master.Transport.WriteTimeout = 300;
                    master.Transport.Retries = 5;
                    btnETHConnect.Enabled = false;
                    //btnETHUnConnect.Enabled = false;
                    timer1.Enabled = true;

                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnETHUnConnect_Click(object sender, EventArgs e)
        {
            if (tcpClient != null)
            {
                GlobalParams.ConnectState = false;
                tcpClient.Close();
                //if(tcpClient != null)
                btnETHConnect.Enabled = true;
                btnETHUnConnect.Enabled = true;
                tcpClient = null;
                timer1.Enabled = false;
            }
        }

        private void btnRU_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 5;
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 15;
        }




        public bool Send0x06CmdFun(ushort addrModbus, ushort dataModbus)                                            //发送函数
        {
            try
            {
                if (master == null)
                    return false;

                master.WriteSingleRegister((byte)Convert.ToInt32(textBoxETHID.Text), addrModbus, dataModbus);    //写入值到模拟输出寄存器，(从站地址、寄存器地址、写入值)
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return true;
            }
        }

        public bool Read0x03CmdFun(ushort addrModbus, ushort dataModbus, ref ushort[] BuffModbus)       //读取函数，ref将函数中改变了的BuffModbus变量反映在函数上
        {
            try
            {
                if (master == null)
                    return false;
                BuffModbus = master.ReadHoldingRegisters((byte)Convert.ToInt32(textBoxETHID.Text), addrModbus, dataModbus);//读取模拟输出寄存器值，(从站地址、起始地址、读取数量)
                return true;
            }
            catch (Exception ex)
            {
                EthUnConnectFun();
                MessageBox.Show(ex.Message);
                return false;
            }

        }

        private void timer1_Tick(object sender, EventArgs e)                //定时发送指令
        {
            if (tcpClient == null)
            {
                GlobalParams.ConnectState = false;
            }
            else
            {
                GlobalParams.ConnectState = true;
            }

            if (isSendData)
            {
                ushort temp;
                if (sendCmd == 15)
                    temp = (sendCmd);
                else
                    temp = (ushort)(sendCmd | 0x10);
                Send0x06CmdFun(0x0F, temp);                                         //写入0X0F中
                isSendData = false;
            }
            else
            {
                ushort[] SysReg = null;
                if (Read0x03CmdFun(0, 3, ref SysReg) == true)               //从地址0连续读取3个数量地址，传到数组SysReg
                {
                    flat_lightA = (SysReg[1] >> 2) & 0x01;                           //数组中第二个值移除B1-B0位，并与0X01位与后，用于只判断灯A开断，1：开，0关，传送
                    if (flat_lightA == 1)                                                         //灯A状态显示
                    {
                        labelLightStateA.Text = "开";
                    }
                    else
                    {
                        labelLightStateA.Text = "关";
                    }
                    if (flat_lightB == 1)                                                           //灯B状态显示
                    {
                        labelLightStateB.Text = "开";
                    }
                    else
                    {
                        labelLightStateB.Text = "关";
                    }
                    float temp;
                    temp = SysReg[2];                                                        //数组中第三个值传送
                    labPowerVol.Text = (temp / 10).ToString() + " V";
                    int platmode;
                    platmode = (SysReg[1] >> 4) & 0x0F;                         //数组中第二个值移除B3-B0位，并与0X0F位与后，用于只判断运动模式，传送
                    if ((SysReg[1] & 0x0001) == 0)                                     //如果B0位为0，说明当前停止
                        platmode = 16;
                    switch (platmode)
                    {
                        case 0:
                            lbMode.Text = "模式：上";
                            break;
                        case 1:
                            lbMode.Text = "模式：下";
                            break;
                        case 2:
                            lbMode.Text = "模式：左";
                            break;
                        case 3:
                            lbMode.Text = "模式：右";
                            break;
                        case 4:
                            lbMode.Text = "模式：左上";
                            break;
                        case 5:
                            lbMode.Text = "模式：右上";
                            break;
                        case 6:
                            lbMode.Text = "模式：左下";
                            break;
                        case 7:
                            lbMode.Text = "模式：聚拢";
                            break;
                        case 8:
                            lbMode.Text = "模式：右下";
                            break;
                        case 9:
                            lbMode.Text = "模式：垂直居中";
                            break;
                        case 10:
                            lbMode.Text = "模式：水平居中";
                            break;
                        case 11:
                            lbMode.Text = "模式：打散";
                            break;
                        case 12:
                            lbMode.Text = "模式：翻面";
                            break;
                        case 15:
                            lbMode.Text = "模式：停止";
                            break;
                        default:
                            lbMode.Text = "模式:  停止";
                            break;
                    }
                }
            }
        }


        private void btnLU_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 4;
        }

        private void btnSendMotorParam_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 0;
        }

        private void btnL_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 2;
        }

        private void btnJL_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 7;
        }

        private void btnR_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 3;
        }


        public void EthUnConnectFun()
        {

            if (tcpClient != null)
            {
                tcpClient.Close();
                btnETHConnect.Enabled = true;
                btnETHUnConnect.Enabled = true;
                tcpClient = null;
                timer1.Enabled = false;
            }
        }

        private void btnLD_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 6;
        }

        private void btnDown_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 1;
        }

        private void btnRL_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 8;
        }

        private void btnV_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 9;
        }

        private void btnDS_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 11;
        }

        private void btnH_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 10;
        }

        private void btnGroup1_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 14;
        }

        private void btnGroup2_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 13;
        }

        private void btnFM_Click(object sender, EventArgs e)
        {
            isSendData = true;
            sendCmd = 12;
        }


        private void btnLightonA_Click(object sender, EventArgs e)         //灯A开启 
        {
            Send0x06CmdFun(0x06, 0XFF00);
            if (flat_lightA == 1)
            {
                flat_lightA = 0;
                labelLightStateA.Text = "开";
            }
        }

        private void btnLightoffA_Click(object sender, EventArgs e)         //灯A关闭
        {
            Send0x06CmdFun(0x06, 0X00);
            if (flat_lightA == 1)
            {
                flat_lightA = 0;
                labelLightStateA.Text = "关";
            }
        }

        private void btnlightAset_Click(object sender, EventArgs e)             //灯A亮度限制
        {
            if (Convert.ToInt32(tblightAvalue.Text) > 999 || Convert.ToInt32(tblightAvalue.Text) < 6)
            {
                MessageBox.Show("超过可设置范围", "警告", MessageBoxButtons.OK);
            }
            else
            {
                ushort value = Convert.ToUInt16(tblightAvalue.Text);
                trk_lightbrightA.Maximum = value;
                Send0x06CmdFun(0x52, value);
            }
        }

        private void trk_lightbrightA_Scroll(object sender, EventArgs e)     //灯A亮度滑动改变
        {
            if (flat_lightA == 1)
            {
                ushort x = Convert.ToUInt16(trk_lightbrightA.Value);
                try
                {
                    Send0x06CmdFun(0x50, x);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        private void btnlightBset_Click(object sender, EventArgs e)             //灯B亮度限制
        {
            if (Convert.ToInt32(tblightBvalue.Text) > 999 || Convert.ToInt32(tblightBvalue.Text) < 6)
            {
                MessageBox.Show("超过可设置范围", "警告", MessageBoxButtons.OK);
            }
            else
            {
                ushort value = Convert.ToUInt16(tblightBvalue.Text);
                trk_lightbrightB.Maximum = value;
                Send0x06CmdFun(0x53, value);
            }
        }

        private void trk_lightbrightB_Scroll(object sender, EventArgs e)        //灯B亮度滑动改变
        {
            if (flat_lightB == 1)
            {
                ushort x = Convert.ToUInt16(trk_lightbrightB.Value);
                try
                {
                    Send0x06CmdFun(0x51, x);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        private void btnBox_Click(object sender, EventArgs e)                       //料仓震动开启
        {
            Send0x06CmdFun(0x05, 0xff00);
        }

        private void btnBoxoff_Click(object sender, EventArgs e)                      //料仓震动关闭
        {
            Send0x06CmdFun(0x05, 0x00);
        }

        private void btnBoxfreSet_Click(object sender, EventArgs e)                 //料仓频率设定
        {
            float fr = Convert.ToSingle(tbBoxfre.Text);
            if (fr < 10 || fr > 400)
            {
                MessageBox.Show("频率设定超过范围");
                return;
            }
            ushort x = Convert.ToUInt16(fr * 10.0F);
            Send0x06CmdFun(0xc1, x);

        }

        private void btnMethod1Set_Click(object sender, EventArgs e)            //组合一设置
        {
            try
            {
                ushort MODE = 0;                         //组合模式选择赋值

                ushort[] DATA = new ushort[16];
                byte sid = Convert.ToByte(textBoxETHID.Text);
                master.WriteMultipleRegisters(sid, 0x60, DATA);                           //先清除组合一的方法

                //Send0x06CmdFun(0x61, 0);                                                                
                //Send0x06CmdFun(0x63, 0);
                //Send0x06CmdFun(0x65, 0);
                //Send0x06CmdFun(0x67, 0);
                //Send0x06CmdFun(0x69, 0);
                //Send0x06CmdFun(0x6b, 0);
                //Send0x06CmdFun(0x6d, 0);
                //Send0x06CmdFun(0x6f, 0);
                //ushort[] address = new ushort[16];
                //for (int i = 0; i < address.Length; i++)
                //{
                //    address[i] = 0x60 + Convert.ToUInt16( i);
                //    Send0x06CmdFun(address[i],0x00);

                //}


                if ((String.IsNullOrEmpty(cmbSTEP1.Text) && String.IsNullOrEmpty(cmbSTEP2.Text) && String.IsNullOrEmpty(cmbSTEP3.Text) && String.IsNullOrEmpty(cmbSTEP4.Text))
                    || (cmbSTEP1.Text == "请选择" && cmbSTEP2.Text == "请选择" && cmbSTEP3.Text == "请选择" && cmbSTEP4.Text == "请选择"))     //模式框和时间框无内容
                {
                    MessageBox.Show("请至少设置一个步骤");
                    return;
                }
                /***************组合一步骤1***********************/
                if (!string.IsNullOrEmpty(cmbSTEP1.Text) && cmbSTEP1.Text != "请选择")                         //步骤一模式框判断有无内容，如果有内容
                {
                    if (String.IsNullOrEmpty(tbTIME1.Text))                                                                             //步骤一时间框判断有无内容，如果无内容
                    {
                        MessageBox.Show("请输入步骤1时间");
                        return;
                    }
                    else
                    {
                        float ft1 = Convert.ToSingle(tbTIME1.Text);
                        if (ft1 < 0.1 || ft1 > 20.0)
                        {
                            MessageBox.Show("步骤1时间值超过范围！");
                            return;
                        }

                        ushort t1 = ChooseMode(cmbSTEP1, MODE);
                        if (t1 == 15)                                                                                            //输入了其他内容
                        {
                            MessageBox.Show("输入错误！！");
                            return;
                        }
                        Send0x06CmdFun(0x60, t1);                                                                   //组合一步骤1模式写入

                        ushort ut1 = Convert.ToUInt16(ft1 * 10.0F);
                        Send0x06CmdFun(0x61, ut1);                                                                 //组合一步骤1时间写入
                    }


                }
                /***************组合一步骤2***********************/
                if (!string.IsNullOrEmpty(cmbSTEP2.Text) && cmbSTEP2.Text != "请选择")                                        //步骤2模式框判断有无内容，如果有内容
                {
                    if (String.IsNullOrEmpty(tbTIME2.Text))                                                                                         //步骤2时间框判断有无内容，如果无内容
                    {
                        MessageBox.Show("请输入步骤2时间");
                        return;
                    }
                    else
                    {
                        float ft1 = Convert.ToSingle(tbTIME2.Text);
                        if (ft1 < 0.1 || ft1 > 20.0)
                        {
                            MessageBox.Show("步骤2时间值超过范围！");
                            return;
                        }
                        ushort t1 = ChooseMode(cmbSTEP2, MODE);
                        if (t1 == 15)                                                                                //输入了其他内容
                        {
                            MessageBox.Show("输入错误！！");
                            return;
                        }
                        Send0x06CmdFun(0x62, t1);                                                        //组合一步骤2模式写入

                        ushort ut1 = Convert.ToUInt16(ft1 * 10.0F);
                        Send0x06CmdFun(0x63, ut1);                                                      //组合一步骤2时间写入
                    }
                }
                /***************组合一步骤3***********************/
                if ((!string.IsNullOrEmpty(cmbSTEP3.Text)) && cmbSTEP3.Text != "请选择")                                   //步骤3模式框判断有无内容，如果有内容
                {
                    if (String.IsNullOrEmpty(tbTIME3.Text))                                                                                         //步骤3时间框判断有无内容，如果无内容
                    {
                        MessageBox.Show("请输入步骤3时间");
                        return;
                    }
                    else
                    {
                        float ft1 = Convert.ToSingle(tbTIME3.Text);
                        if (ft1 < 0.1 || ft1 > 20.0)
                        {
                            MessageBox.Show("步骤3时间值超过范围！");
                            return;
                        }
                        ushort t1 = ChooseMode(cmbSTEP3, MODE);
                        if (t1 == 15)                                                                                //输入了其他内容
                        {
                            MessageBox.Show("输入错误！！");
                            return;
                        }
                        Send0x06CmdFun(0x64, t1);                                                       //组合一步骤3模式写入

                        ushort ut1 = Convert.ToUInt16(ft1 * 10.0F);
                        Send0x06CmdFun(0x65, ut1);                                                      //组合一步骤3时间写入


                    }
                }

                /***************组合一步骤4***********************/
                if (!string.IsNullOrEmpty(cmbSTEP4.Text) && cmbSTEP4.Text != "请选择")                                             //步骤4模式框判断有无内容，如果有内容
                {
                    if (String.IsNullOrEmpty(tbTIME4.Text))                                                                                                //步骤4时间框判断有无内容，如果无内容
                    {
                        MessageBox.Show("请输入步骤4时间");
                        return;
                    }
                    else
                    {
                        float ft1 = Convert.ToSingle(tbTIME4.Text);
                        if (ft1 < 0.1 || ft1 > 20.0)
                        {
                            MessageBox.Show("步骤4时间值超过范围！");
                            return;
                        }
                        ushort t1 = ChooseMode(cmbSTEP4, MODE);
                        if (t1 == 15)                                                                                //输入了其他内容
                        {
                            MessageBox.Show("输入错误！！");
                            return;
                        }
                        Send0x06CmdFun(0x66, t1);                                                        //组合一步骤4模式写入

                        ushort ut1 = Convert.ToUInt16(ft1 * 10.0F);
                        Send0x06CmdFun(0x67, ut1);                                                      //组合一步骤4时间写入
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR");
            }
        }



        public ushort ChooseMode(ComboBox comboBox, ushort Num)
        {
            string temp = comboBox.Text.Trim();
            switch (temp)
            {
                case "上":
                    Num = 0;
                    break;
                case "下":
                    Num = 1;
                    break;
                case "左":
                    Num = 2;
                    break;
                case "右":
                    Num = 3;
                    break;
                case "左上":
                    Num = 4;
                    break;
                case "右上":
                    Num = 5;
                    break;
                case "左下":
                    Num = 6;
                    break;
                case "聚拢":
                    Num = 7;
                    break;
                case "右下":
                    Num = 8;
                    break;
                case "垂直居中":
                    Num = 9;
                    break;
                case "水平居中":
                    Num = 10;
                    break;
                case "振散":
                    Num = 11;
                    break;
                case "翻面":
                    Num = 12;
                    break;
                default:
                    Num = 15;
                    break;

            }
            return Num;
        }

        private void btnPlatfreSet_Click(object sender, EventArgs e)                    //各个运动模式频率设定
        {

            if (string.IsNullOrEmpty(cmbPlatMode.Text) || cmbPlatMode.Text == "请选择")
            {
                MessageBox.Show("请选择需要修改的频率");
                return;
            }
            else
            {
                if (string.IsNullOrEmpty(tbPlatfre.Text))
                {
                    MessageBox.Show("请输入频率");
                    return;
                }
                else
                {
                    if (Convert.ToInt32(tbPlatfre.Text) < 10 || Convert.ToInt32(tbPlatfre.Text) > 200)
                    {
                        MessageBox.Show("频率设置超出范围");
                        return;
                    }
                }
                float f1 = Convert.ToSingle(tbPlatfre.Text);
                ushort address = 0;
                ushort temp = PlatFrequency(cmbPlatMode, ref address);                  //获取选择模式的地址
                if (temp == 99)
                {
                    MessageBox.Show("频率模式错误！！");
                }
                float fre = Convert.ToSingle(tbPlatfre.Text) * 10.0F;                               //获取频率并换算
                Send0x06CmdFun(temp, Convert.ToUInt16(fre));                                //写入频率
            }
        }

        private void btnPlatVSet_Click(object sender, EventArgs e)                          //震动平台电压设定
        {
            if (string.IsNullOrEmpty(cmbPlatVMode.Text) || cmbPlatVMode.Text == "请选择")
            {
                MessageBox.Show("请选择需要修改的电压");
                return;
            }
            else
            {
                if (string.IsNullOrEmpty(tbPlatV.Text))
                {
                    MessageBox.Show("请输入电压");
                    return;
                }
                else
                {
                    if (Convert.ToInt32(tbPlatV.Text) < 0 || Convert.ToInt32(tbPlatV.Text) > 24)
                    {
                        MessageBox.Show("电压设置超出范围");
                        return;
                    }
                }
                ushort address = 0;
                ushort temp = Convert.ToUInt16(PlatFrequency(cmbPlatVMode, ref address) + 0x01);//获取选择模式地址
                if (temp == 100)
                {
                    MessageBox.Show("频率模式错误！！");
                    return;
                }
                float v1 = Convert.ToSingle(tbPlatV.Text) * 10.0F;                                   //获取电压值并换算
                Send0x06CmdFun(temp, Convert.ToUInt16(v1));                                      //写入电压
            }
        }


        public ushort PlatFrequency(ComboBox cmb, ref ushort address)
        {

            string temp = cmb.Text.Trim();
            switch (temp)
            {
                case "上":
                    address = 16;
                    break;
                case "下":
                    address = 19;
                    break;
                case "左":
                    address = 22;
                    break;
                case "右":
                    address = 25;
                    break;
                case "左上":
                    address = 28;
                    break;
                case "右上":
                    address = 31;
                    break;
                case "左下":
                    address = 34;
                    break;
                case "右下":
                    address = 37;
                    break;
                case "垂直居中":
                    address = 40;
                    break;
                case "水平居中":
                    address = 43;
                    break;
                case "振散":
                    address = 46;
                    break;
                case "翻面":
                    address = 52;
                    break;
                default:
                    address = 99;
                    break;

            }
            return address;
        }

		#endregion UI_Clicked

		private void buttonTrans1_Click(object sender, EventArgs e)
		{
            try
            {
                float u = Convert.ToSingle(textBoxU.Text);
                float v = Convert.ToSingle(textBoxV.Text);
                var xy = GlobalParams.cves[1].GetRealPt(u, v);
                textBoxX.Text = xy.X.ToString("F2");
                textBoxY.Text = xy.Y.ToString("F2");
            }
            catch(Exception ex)
			{
                MessageBox.Show(this, ex.Message, "ERROR");
			}
        }

		private void buttonTrans2_Click(object sender, EventArgs e)
		{
            try
            {
                float x = Convert.ToSingle(textBoxX.Text);
                float y = Convert.ToSingle(textBoxY.Text);
            }
            catch(Exception ex)
			{
                MessageBox.Show(this, ex.Message, "ERROR");
            }
        }
	}
}

